package servlet;

import com.alibaba.fastjson.JSON;
import dao.StudentDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * @Author leiHua
 * @Date 2022/12/17 16:45
 */
@WebServlet("/student")
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StudentDao studentDao = new StudentDao();
        try {
            Map<String, Object> data = studentDao.queryNumByGender();
            System.out.println(JSON.toJSON(data).toString());
            response.setContentType("text/html;charset=utf-8");
            PrintWriter writer = response.getWriter();
            writer.write(JSON.toJSON(data).toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
